//
//  main.swift
//  DutyChainPattern
//
//  Created by mac on 2017/11/7.
//  Copyright © 2017年 RRC. All rights reserved.
//

import Foundation

print("Hello, World!")

var arrayList = Array<Women>()
for _ in 0..<5{
    arrayList.append(Women(type: Int(arc4random()%4), request: "我要出去逛街"))
}

let father:Handler = Father()
let husband:Handler = Husband()
let son:Handler = Son()
//设置请求顺序
father.setNext(handle: husband)
husband.setNext(handle: son)

for women in arrayList {
//    if women.getType() == 1 {
//        print("------------女儿向父亲请示---------")
//        father.HandleMessage(women: women)
//    }else if women.getType() == 2 {
//        print("------------妻子向丈夫请示----------")
//        husband.HandleMessage(women: women)
//    }else if women.getType() == 3 {
//        print("------------母亲向儿子请示----------")
//        son.HandleMessage(women: women)
//    }
    father.HandleMessage(women: women)
}

/**
 责任链模式定义：使多个对象都有机会处理请求，从而避免了请求的发送者和接受者之间的耦合关系。将这些对象连成一条链，并沿着这条链传递该请求，直到有对象处理它为止。
 */

